package com.cms.common.kit;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.cms.model.Res;

/**
 * 常用辅助工具类
 * @author Administrator
 *
 */
public class Tools {
	
	private final static Logger logger=LoggerFactory.getLogger(Tools.class);
	
	/**
	 * 生成32UUID
	 * @return
	 */
	public static String generUUID32(){
		return UUID.randomUUID().toString().replace("-", "");
	}
	
	public static List<Tree> transferTree(List<Res> res,int pid){
		List<Tree> t_list=new ArrayList<>();
		List<Tree> children=null;
		Tree t=null;
		for (Res res2 : res) {
			t=new Tree();
			t.setId(res2.getInt("id"));
			t.setpId(res2.getInt("pId"));
			t.setText(res2.getStr("text"));
			t.setUrl(res2.getStr("url"));
			if(0==res2.getInt("pId")){
				t_list.add(t);
			}
		}
		for (Tree tree : t_list) {
			children=new ArrayList<Tree>();
			for (Res res2 : res) {
				t=new Tree();
				t.setId(res2.getInt("id"));
				t.setpId(res2.getInt("pId"));
				t.setText(res2.getStr("text"));
				t.setUrl(res2.getStr("url"));
				if(tree.getId()==res2.getInt("pId")){
					children.add(t);
				}
			}
			tree.setChildren(children);
		}
		return t_list;
	}
}
